<template>
  <el-form ref="form" :model="form" label-width="150px">
    <el-form-item label="不良现象：">
      <el-input type="textarea" v-model="form.description"></el-input>
    </el-form-item>
    <el-form-item label="不良原因大类：" >
      <el-select v-model="form.reasonID" placeholder="请选择不良原因大类" style="width:250px">
        <el-option
          v-for="item in reason1"
          :key="item.ReasonID"
          :label="item.ReasonID +'  '+ item.Description "
          :value="item.ReasonID"
        ></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="不良原因细类：">
      <el-select v-model="form.reasonDetailID" placeholder="请选择不良原因细类" style="width:250px">
        <el-option
          v-for="(item,index) in reason2"
          :key="index"
          :label="item.ReasonDetailID +'  '+ item.Description "
          :value="item.ReasonDetailID"
        ></el-option>
      </el-select>
    </el-form-item>
<!--    <el-form-item label="解决办法：">-->
<!--      <el-select v-model="form.solutionID" placeholder="请选择解决方法" style="width:250px">-->
<!--        <el-option -->
<!--          v-for="(item,index) in solutionList"-->
<!--          :key="index"-->
<!--          :label="item.SolutionID +'  '+ item.Description " -->
<!--          :value="item.SolutionID"-->
<!--        ></el-option>-->
<!--      </el-select>-->
<!--    </el-form-item>-->
    <el-form-item label="返回工序：">
      <el-select v-model="form.returnTechId" placeholder="请选择返回工序" style="width:250px">
        <el-option
          v-for="(item,index) in techList"
          :key="index"
          :label="item.TechId +'  '+ item.Name "
          :value="item.TechId"
        ></el-option>
      </el-select>
    </el-form-item>
    <!-- <el-checkbox v-model="repeat">是否重打照片</el-checkbox> -->

    <el-form-item>
      <el-button type="primary" @click="onSubmit" style="width:250px">处理完成</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import {commitMaintainOrderProduct, //维修提交
getQcReasonList, //不良原因大类
getQcReasonDetailList, // 不良原因细类
getQcSolutionList, // 解决办法
} from '@/api/maintain'
import {getTechPageList} from '@/api/process'  // 获取工序
  export default {
    props:['productCode'],
    data() {
      return {
        form: {
          // productCode:'',
          description: '',
          reasonID:'',
          reasonDetailID:'',
          solutionID:'',
          returnTechId:''
        },
        repeat:'',
        reason1:[],
        reason2:[],
        solutionList:[],
        techList:[],
      }
    },
    mounted() {
      this.init();
    },
    methods: {
      init(){
        //不良原因大类
        getQcReasonList().then(res => {
          if(parseInt(res.Code) === 1){
            this.reason1 = res.Result
          }

        })

        //不良原因细类
        getQcReasonDetailList().then(res => {
          if(parseInt(res.Code) === 1){
            // alert('ok my god')
            this.reason2 = res.Result
          }
        })

        //解决办法
        getQcSolutionList().then(res =>{
          if(parseInt(res.Code) === 1){
            this.solutionList = res.Result
          }
        })

        // 返回工序
        getTechPageList({keyName:'',page:1,pageSize:1000}).then(res => {
          if(parseInt(res.Code) === 1){
            this.techList = res.Result.Items
          }
        })
      },

      onSubmit() {
        let listid=''
        this.$parent.checkIds.forEach(el => {
            listid+=el+','
        });
        listid=listid.substr(0,listid.length-1)
        console.log(listid)
        let data = {
          orderProductPartId:this.$parent.productData.OrderProductPartId,
          strOrderFileId:listid,
          description:this.form.description,
          reasonID:this.form.reasonID,
          reasonDetailID:this.form.reasonDetailID,
          solutionID:this.form.solutionID,
          returnTechId:this.form.returnTechId
        }
        commitMaintainOrderProduct(data).then(res => {
          if(parseInt(res.Code) === 1) {
            this.$message({
              type: 'success',
              message: res.Message
            })
             this.$parent.tableData = []
            this.form = {}
          }
        }).catch(res => {
            // this.$parent.tableData = []
            // this.form = {}
        });
      }
    }
  }
</script>
<style scoped lang="scss">
.el-checkbox{
  margin-left: 150px;
  margin-bottom: 20px;
}
</style>
